package net.lagou.mathsort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author zhangwei
 * @date 2020/8/11  23:40
 * @jdkversion 1.8
 * @description xxxx
 */
public class NumberReducer extends Reducer<LongWritable, NullWritable, NumberBean, NullWritable> {
    NumberBean numberBean = new NumberBean();
    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        long serial =1;
        for (NullWritable value : values) {
            if(key==null){
                continue;
            }
            numberBean.setSerial(serial++);
            numberBean.setNumber(key.get());
            context.write(numberBean,NullWritable.get());
        }
    }
}
